<?php
$width=Yii::app()->params['dialog']['findTruckForAccident']['width'];
$height=Yii::app()->params['dialog']['findTruckForAccident']['height'];
$width1=Yii::app()->params['dialog']['findDriverForAccident']['width'];
$height1=Yii::app()->params['dialog']['findDriverForAccident']['height'];
$cs=Yii::app()->clientScript;
$cs->registerScriptFile('./js/modal.js');
$cs->registerScript('driver_accident_dialog',<<<END
function Block(){\$.modal('?r=dialog/findTruckForAccident',{width:$width,height:$height,title:'请选择车辆'});return false;}
function Block1(){\$.modal('?r=dialog/findDriverForAccident',{height:$height1,width:$width1,title:'请选择司机'});return false;}
$("#findTruck").click(Block);
$("#findDriver").click(Block1);
function make_name(info){\$(info).each(function(i,item){\$(item).find("input[type!=button],textarea").each(function(n,obj){var re=/\d{1,10}/g;obj.name=obj.name.replace(re,String(i));});});}
var info_n=100;function info(main,info,add_btn,del_btn,sh_btn){this.main=main;this.info=info;this.init=function(){\$(add_btn).click(this.add_info);$(del_btn).click(this.del_info);}
this.add_info=function(){info_n+=1;if($(sh_btn).attr('class')=='hide') $(sh_btn).click();
var f=$(info+":first").clone(true);f.find("input[type!=button],textarea").val('').removeClass('error').each(function(i,obj){var re=/\d{1,10}/g;obj.id=obj.id.replace(re,info_n);});f.find('input[type!=button]:last').val(0);f.find("span[class=error]").remove();f.appendTo(main);make_name(info);}
$(sh_btn).click(function(){if($(this).attr('class')=='show'){\$(main).hide(300);$(this).attr('class','hide').val('显示');$("#info_line").hide();}else{\$(main).show(300);$(this).attr('class','show').val('隐藏');$("#info_line").show();}});this.del_info=function(){if($(info).length<2)return;$(this).parents(info).remove();make_name(info);}}
var t=new info("#main",".detail_info","#add_detail",'.del_detail','#sh_detail');t.init();
$("#calculate").click(function(){
	var vaild=true;
	var validator=$("form").validate();//alert(validator.element($('#Accident_record_plate_no')));
	var cost=0;
	validator.resetForm();
	$("#main").find("input[type!=button]:odd").each(function(i,item){vaild=validator.element($(item))?vaild:false;});
	vaild=validator.element($('#Accident_record_compensation_amount'))?vaild:false;
	vaild=validator.element($('#Accident_record_driver_share_rate'))?vaild:false;
	if(!vaild) {alert('请将信息填写完整信息!');return;}
	$("#main").find("input[type!=button]:odd").each(function(i,item){cost+=parseFloat($(item).val(),10);});
	$("#Accident_record_accident_cost").val(Math.round(cost*100)/100);
	var cost_margin=Number($('#Accident_record_accident_cost').val())-Number($('#Accident_record_compensation_amount').val());
	$("#Accident_record_cost_margin").val(Math.round(cost_margin*100)/100);
	if(cost_margin<0){
		$('#Accident_record_ulti_loss_amount').val(Math.round(cost_margin*100)/100);
		return;	
	}
	var driver_cost=$('#Accident_record_cost_margin').val()*$("#Accident_record_driver_share_rate").val()/100;
	$('#Accident_record_ulti_loss_amount').val(Math.round((cost_margin-driver_cost)*100)/100);
});
$('form').submit(function(){\$("#calculate").click();});
END
)
?>
<div class="yiiForm">
<?php
	echo EHtml::form();	
	EHtml::setOptions(array('errorElement'=> 'span'));
	EHtml::setScenario($update ? 'update' : 'create');				  		
?>
<div>注：<span class="required">*</span>为必填项</div>
<div id="leftaa">
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'plate_no'); ?>
<?php echo EHtml::activeTextField($model,'plate_no',array('size'=>7,'class'=>'readonly','readOnly'=>'true')); ?>
<?php echo CHtml::activeHiddenField($model,'fk_truck_id');?>&nbsp;&nbsp;<a id="findTruck" href="#">查找车辆</a>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'property_owner',array('size'=>10)); ?>
<?php echo EHtml::activeTextField($model,'property_owner',array('size'=>25,'maxlength'=>100,'class'=>'readonly','readOnly'=>'true')); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'driver_name'); ?>
<?php echo EHtml::activeTextField($model,'driver_name',array('size'=>7,'class'=>'readonly','readOnly'=>'true')); ?>
<?php echo CHtml::activeHiddenField($model,'fk_driver_id');?>&nbsp;&nbsp;<a id="findDriver" href="#">查找司机</a>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'accident_date'); ?>
<?php if($update):?>
<?php echo EHtml::activeTextField($model,'accident_date',array("id"=>"accident_date",'size'=>14,'value'=>substr($model->accident_date,0,16))); ?>
<?php else:?>
<?php echo EHtml::activeTextField($model,'accident_date',array("id"=>"accident_date",'size'=>14)); ?>
<?php endif;?>
<?php $this->widget('application.extensions.calendar.SCalendar',array('inputField'=>'accident_date','ifFormat'=>'%Y-%m-%d %H:%M','showsTime'=>true));?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'accident_place'); ?>
<?php echo EHtml::activeTextField($model,'accident_place',array('size'=>20,'maxlength'=>50)); ?>
</div>
</div>
  <div id="rightaa">
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'case_end_date'); ?>
<?php echo EHtml::activeTextField($model,'case_end_date',array("id"=>"case_end_date",'size'=>10)); ?>
<?php $this->widget('application.extensions.calendar.SCalendar',array('inputField'=>'case_end_date','ifFormat'=>'%Y-%m-%d',));?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'accept_company'); ?>
<?php echo EHtml::activeTextField($model,'accept_company',array('size'=>20,'maxlength'=>100)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'agent'); ?>
<?php echo EHtml::activeTextField($model,'agent',array('size'=>8,'maxlength'=>30)); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'compensation_received_date'); ?>
<?php echo EHtml::activeTextField($model,'compensation_received_date',array("id"=>"compensation_received_date",'size'=>10)); ?>
<?php $this->widget('application.extensions.calendar.SCalendar',array('inputField'=>'compensation_received_date','ifFormat'=>'%Y-%m-%d',));?>
</div>
<div class="simple">
</div>
</div>
<div class="simple4">
<?php echo CHtml::activeLabelEx($model,'accident_detail'); ?>
<?php echo EHtml::activeTextArea($model,'accident_detail',array('rows'=>6, 'cols'=>65, 'maxlength'=>500)); ?>
</div>
<div style="width:735px;	border:1px solid #90b3bc;margin:0px auto;border-top:0px;margin-bottom:-1px;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="add_detail" type="button" value="添加事故费用明细"/><input id="sh_detail" class="show" type="button" value="隐藏"/>
</div>

<div id="main" style="width:735px;background-color: #ebf4fb; border:1px solid #90b3bc;margin-left:-11px;margin-right:-11px;margin:0px auto;border-bottom:0px;">
<?php
	foreach($detail_models as $n=>$detail_model):
?>
<table class="detail_info" width="100%"   border="0"   cellpadding="0"   cellspacing="0"   bgcolor="#90b3bc">
<tr>
<td width="122"  bgcolor="#ffffff" align="right" height="30"><?php echo CHtml::activeLabelEx($detail_model,'cost_name'); ?></td>
<td  bgcolor="#ffffff">&nbsp;<?php echo EHtml::activeTextField($detail_model,'cost_name',
	array('class'=>'required','name'=>"detail[{$n}][cost_name]",'size'=>15,'maxlength'=>50)); ?></td>
<td bgcolor="#ffffff" align="right" height="30"><?php echo CHtml::activeLabelEx($detail_model,'cost_amount'); ?></td>
<td  bgcolor="#ffffff">&nbsp;<?php echo EHtml::activeTextField($detail_model,'cost_amount',
	array('class'=>'required','name'=>"detail[{$n}][cost_amount]",'size'=>7,'number'=>'ture','my_float'=>18.2)); ?>
	&nbsp;&nbsp;&nbsp;&nbsp;<input class="del_detail"  type="button" value="删除"/>
</td>
</tr>

<tr>
<td colspan="4"  height="1"></td>
</tr>
</table><!--linkman_info-->
<?php 
endforeach;
?>
</div><!-- main -->
<div id="info_line" style=" height:20px;width:735px;	border:1px solid #90b3bc;margin:0px auto;border-top:0px;margin-bottom:-1px;">
</div>
<div id="leftaa">
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'accident_cost'); ?>
<?php echo EHtml::activeTextField($model,'accident_cost',array('size'=>8)); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'cost_margin'); ?>
<?php echo EHtml::activeTextField($model,'cost_margin',array('size'=>8)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'ulti_loss_amount'); ?>
<?php echo EHtml::activeTextField($model,'ulti_loss_amount',array('size'=>8)); ?>
</div>
</div>
<div id="rightaa" >
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'compensation_amount'); ?>
<?php echo EHtml::activeTextField($model,'compensation_amount',array('size'=>8)); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'driver_share_rate'); ?>
<?php if($update):?>
<?php echo EHtml::activeTextField($model,'driver_share_rate',array('value'=>$model->driver_share_rate*100)); ?>
<?php else:?>
<?php echo EHtml::activeTextField($model,'driver_share_rate',array('size'=>8)); ?>
<?php endif;?>
</div>
<div class="simple"><input id="calculate" type="button" value="计算"/></div>
</div>
<div class="action">
<?php echo EHtml::submitButton($update ? '更新信息' : '添加信息'); ?>
</div>

<?php echo EHtml::endForm(); ?>

</div><!-- yiiForm -->